<template>
  <div class="chat-container">
    <!-- 导航栏 -->
    <van-nav-bar class="app-nav-bar" title="小智同学" left-arrow fixed />
    <!-- /导航栏 -->

    <!-- 消息列表 -->
    <div class="message-list" ref="message-list">
      <van-cell-group>
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
        <van-cell title="单元格" value="内容" />
      </van-cell-group>
    </div>
    <!-- /消息列表 -->

    <!-- 发送消息 -->
    <van-cell-group class="send-message">
      <van-field center clearable>
      </van-field>
      <van-button size="small" type="primary" @click="onSendMessage">发送</van-button>
    </van-cell-group>
    <!-- /发送消息 -->
  </div>
</template>

<script>
// 导入websocket
// import { io } from 'https://cdn.socket.io/4.3.2/socket.io.esm.min.js'
export default {
  name: 'chatPage',

  data() {
    return {
      // websocket实例对象
      socket: null,
      // 发送信息
      message: ''
    }
  },

  created() {
    // 初始化建立websocket连接
    // this.socket = io('http://ttapi.research.itcast.cn')
    // this.socket.on('message', data => {})
  },

  methods: {
    // 发消息
    //     onSendMessage(){
    //       this.socket.emit('message', {
    // +        msg: message,
    // +        timestamp: Date.now()
    // +      })
    //     }
  }
}
</script>

<style lang="less" scope>
.chat-container {
  position: absolute;
  width: 100%;
  height: 100%;
  padding: 46px 0 50px 0;
  top: 0;
  left: 0;
  box-sizing: border-box;
  background: #f5f5f6;
  .message-list {
    height: 100%;
    overflow-y: scroll;
    .message-item {
      display: flex;
      flex-flow: row nowrap;
      align-items: flex-start;
      padding: 10px;
      .msg-wrap {
        word-break: break-all;
        word-wrap: break-word;
      }
      .title {
        display: table;
        background: #e0effb;
        border-radius: 6px;
        font-size: 14px;
        padding: 10px 10px;
        margin-right: 45px;
      }
      .avatar {
        width: 40px;
        height: 40px;
        margin-right: 5px;
      }
    }
    .reverse {
      flex-direction: row-reverse;
      .msg-wrap {
        display: flex;
        flex-direction: row-reverse;
        .title {
          margin-right: 5px;
          margin-left: 45px;
        }
      }
    }
  }

  .send-message {
    display: flex;
    align-items: center;
    padding: 0 10px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #f5f5f6 !important;
    .van-field {
      margin-right: 5px;
    }
  }
}
</style>
